package h_10_27;

/**
 * 1004. 最大连续1的个数 III
 * https://leetcode.cn/problems/max-consecutive-ones-iii/description/
 */
public class Main2 {
    public int longestOnes(int[] nums, int k) {
        int n = nums.length;
        int left = 0;
        int right = 0;
        int ret = 0;
        int count = 0;
        while(right < n) {
            int in = nums[right];
            if(in == 0) {
                count++;
            }

            while(count > k) {
                int out = nums[left];
                if(out == 0) {
                    count--;
                }
                left++;
            }

            ret = Math.max(ret,right - left + 1);
            right++;
        }
        return ret;
    }
}
